package com.raycloud.query;

            import java.util.*;
/**
 *
 * @author lvduo (lvduo940613@gmail.com)
 */
public class VersionQuery extends BaseQuery {

	/**==============================批量查询、更新、删除时的Where条件设置==================================**/
	/** version_id **/
    private String versionId;
	public String getVersionId () {
    	return versionId;
   	}
    public VersionQuery setVersionId(String versionId) {
    	this.versionId = versionId;
    	return this;
    }
	/** front_projects_info **/
    private String frontProjectsInfo;
	public String getFrontProjectsInfo () {
    	return frontProjectsInfo;
   	}
    public VersionQuery setFrontProjectsInfo(String frontProjectsInfo) {
    	this.frontProjectsInfo = frontProjectsInfo;
    	return this;
    }
	/** end_projects_info **/
    private String endProjectsInfo;
	public String getEndProjectsInfo () {
    	return endProjectsInfo;
   	}
    public VersionQuery setEndProjectsInfo(String endProjectsInfo) {
    	this.endProjectsInfo = endProjectsInfo;
    	return this;
    }
	/**==============================批量查询时的Order条件顺序设置==================================**/
	public class OrderField{
		public OrderField(String fieldName, String order) {
			super();
			this.fieldName = fieldName;
			this.order = order;
		}
		private String fieldName;
		private String order;
		public String getFieldName() {
			return fieldName;
		}
		public OrderField setFieldName(String fieldName) {
			this.fieldName = fieldName;
			return this;
		}
		public String getOrder() {
			return order;
		}
		public OrderField setOrder(String order) {
			this.order = order;
			return this;
		}
	}

	/**==============================批量查询时的Order条件顺序设置==================================**/
	/**排序列表字段**/
	private List<OrderField> orderFields = new ArrayList<OrderField>();
	/**
	 * 设置排序按属性：version_id
	 * @param isAsc 是否升序，否则为降序
	 */	
	public VersionQuery orderbyVersionId(boolean isAsc){
		orderFields.add(new OrderField("version_id",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：front_projects_info
	 * @param isAsc 是否升序，否则为降序
	 */	
	public VersionQuery orderbyFrontProjectsInfo(boolean isAsc){
		orderFields.add(new OrderField("front_projects_info",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：end_projects_info
	 * @param isAsc 是否升序，否则为降序
	 */	
	public VersionQuery orderbyEndProjectsInfo(boolean isAsc){
		orderFields.add(new OrderField("end_projects_info",isAsc?"ASC":"DESC"));
		return this;
	}
    private String fields;
    /**
     * 提供自定义字段使用
     */
    private static Map<String,String> fieldMap;

    private static Map<String,String> getFieldSet() {
        if (fieldMap == null){
            fieldMap =new HashMap<String,String>();
                    fieldMap.put("version_id", "versionId");
                    fieldMap.put("front_projects_info", "frontProjectsInfo");
                    fieldMap.put("end_projects_info", "endProjectsInfo");
                }
        return fieldMap;
    }

    public String getFields(){
        return this.fields;
    }
    public VersionQuery  setFields(String fields){
        String[] array = fields.split(",");
        StringBuffer buffer = new StringBuffer();
        for (String field : array){
            if(getFieldSet().containsKey(field)){
                buffer.append(field).append(" as ").append(getFieldSet().get(field)).append(" ,");
            }
            if(getFieldSet().containsKey("`"+field+"`")){
                buffer.append("`"+field+"`").append(" as ").append(getFieldSet().get(field)).append(" ,");
            }
        }
        if (buffer.length() != 0){
            this.fields = buffer.substring(0, buffer.length() - 1);
        }else{
            this.fields = " 1 ";//没有一个参数可能会报错
        }
        return this;
    }
}
